<template>
  <div>
    <van-nav-bar title="添加地址" left-arrow>
      <div class="el-icon-arrow-left" slot="left" @click="toBack"></div>
    </van-nav-bar>
    <!-- 输入任意文本 -->
    <van-form @submit="onSubmit">
      <van-field v-model="text" label="联系人" placeholder="你的名字" name="name" />
      <van-field name="sex" label="单选框">
        <template #input>
          <van-radio-group v-model="radio" direction="horizontal">
            <van-radio name="1">先生</van-radio>
            <van-radio name="2">女士</van-radio>
          </van-radio-group>
        </template>
      </van-field>

      <!-- 输入手机号，调起手机号键盘 -->
      <van-field v-model="tel" type="tel" label="联系电话" placeholder="您的手机号" name="phone" />
      <van-field v-model="bTel" type="tel" label="联系电话" placeholder="您的备用 手机号" name="bPhone" />
      <van-field v-model="location" label="送餐地址" placeholder="小区/写字楼/学校等" name="address" />
      <van-field v-model="detail" label="      " placeholder="详细地址（如门牌号等等）" name="detailAddress" />
      <van-field v-model="company" label="标签" placeholder="无/家/学校/公司" name="tag" />
      <van-button type="primary" class="sure" native-type="submit">确定</van-button>
    </van-form>

  </div>
</template>

<script>
import { addDeliveryAddress } from "@/api/reques.js"
export default {
  data() {
    return {
      radio: "",
      tel: '',
      bTel: "",
      text: '',
      location: '',
      detail: '',
      company: '',
      result: [],
    }
  },
  created() {

  },
  methods: {
    toBack(){
      this.$router.back()
    },
    onSubmit(values) {
      console.log(values);
      const user_id = localStorage.getItem("user_id")
      const data  = {
        user_id,
        address: values.address,
        address_detail: values.detailAddress,
        geohash: "23.102562,113.22728",
        name: values.name,
        phone: values.phone,
        tag: values.tag,
        sex: values.sex,
        phone_bk: values.bPhone,
        tag_type: 3
      }
      addDeliveryAddress(data).then((res) => {
        console.log(res);
        this.$router.push("/info")
      })
    
    }
  }

}
</script>

<style lang="scss" scoped>
.van-nav-bar {
  background: rgb(2, 182, 253, 0.7);
}

.sure {
  width: 350px;
  margin: 10px 0 0 12px;
}

.sex {
  margin: 20px 0 20px 118px;
}
</style>
